package servlet;

import dao.UserDaoImpl;
import utils.connect.ConnectSqlDaoImpl;
import utils.string.session.SessionStringUtil;
import utils.string.sql.T_User;
import vo.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;
import java.util.HashMap;
import java.util.logging.Handler;

public class RegisterServlet extends HttpServlet {
    //该对象是为了解决用户注册
    ConnectSqlDaoImpl connectSqlDao = ConnectSqlDaoImpl.getInStance();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //准备就绪进行数据的存储
        String name = req.getParameter("account");
        String password = req.getParameter("password");
        String authority = req.getParameter("authority");
        int auth_id = Integer.valueOf(authority);
        User user = new User();
        user.setAuth_id(auth_id);
        user.setUser_password(password);
        user.setUser_name(name);
        //对数据库中的数据进行修改
        UserDaoImpl userDao = new UserDaoImpl();
        userDao.insertUser(user);
        //数据传递
        HashMap users = userDao.selectAll();
        req.getSession().setAttribute(SessionStringUtil.ALL_USERS,users);
        resp.sendRedirect("/equipmentManager_war_explode/registerSuccess.jsp");
    }
}
